<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/searchform.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    <script src="../viewstyle/config/config2.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div style="text-align: center;">
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="systemApkName" placeholder="应用名称" autocomplete="off">
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" id="btnsearch" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide" id="t" lay-filter="t"></table>

        </div>

    </div>
</div>

</body>

<script type="text/html" id="tb">
    <div class="layui-container">
        <a class="layui-btn layui-btn-sm layui-icon layui-icon-add-1" lay-event="addSystemApk">新增系统应用</a>
        <a class="layui-btn layui-btn-sm layui-icon layui-icon-list" lay-href="yingyong/ShowOrdinaryApk.html">查看普通APK</a>
    </div>
</script>

<script type="text/html" id="caozuo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script>
        var table = layui.table
        table.render({
            elem: '#t',
            id: 'tt',
            toolbar: '#tb',
            url: '/admin/system-apk/searchSystemApkWithPage',
            cols: [
                [{
                    field: 'systemApkId',
                    title: '编号',
                    width: '10%',
                    align: 'center'
                },
                    {
                        field: 'systemApkName',
                        title: '应用名称',
                        width: '10.5%',
                        align: 'center'
                    },
                    {
                        field: 'systemApkPackageName',
                        title: '应用包名',
                        width: '20%',
                        align: 'center'
                    },
                    {
                        field: 'systemApkUrl',
                        title: '文件名',
                        width: '20%',
                        align: 'center'
                    },
                    {
                        field: 'systemApkVesion',
                        title: '版本',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'systemApkVersionName',
                        title: '版本名称',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'systemApkStatus',
                        title: '是否升级',
                        width: '10%',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        fixed: 'right',
                        width: '10%',
                        align: 'center',
                        toolbar: '#caozuo'
                    }
                ]
            ],
            page: true,
        });

        //搜索
        $("#btnsearch").click(function() {
            table.reload('tt', {
                where: {
                    "systemApkName": $('#systemApkName').val()
                },
                page: {
                    curr: 1
                }
            })
        });

        //键盘回车监听
        $(window).keypress(function (event) {
            if(event.which === 13){
                $('#btnsearch').click();
            }
        })

        //添加和返回的监听事件
        table.on('toolbar(t)', function (obj) {
            var e = obj.event;
            switch (e) {
                case 'addSystemApk':
                    layer.open({
                        title:"新增系统应用",
                        content:"AddSystemApk.html",
                        type:2,
                        area:["100%","100%"]
                    })
                    break;
            }
        })

        //   右侧tool监听事件
        table.on('tool(t)', function(obj) {
            var data = obj.data; //获得当前行数据
            var e = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            switch(e) {

                case "edit":
                    layui.data("s", {
                        key: "systemapk",
                        value: data
                    }); //存值
                    layer.open(
                        {
                            title: '编辑系统应用',
                            content: 'EditSystemApk.html',
                            type: 2,
                            area: ['100%', '100%'],
                            end:function () {
                                $(".layui-laypage-btn").click();
                            }
                        }
                    )
                    break;

                case "del":
                    var lay = layer.confirm("确认删除吗?", {
                            title: "信息",
                            btn: ["确定", "取消"]
                        },
                        function(index) {
                            $.ajax({
                                type: "post",
                                url:'/admin/system-apk/deleteSystemAPKById',
                                data: {
                                    systemApkId: data.system_apk_id
                                },
                                success: function(res) {
                                    if(res.code == 200) {
                                        $(tr).remove();
                                        layer.msg("删除成功", {
                                            icon: 1
                                        });
                                        return;
                                        setTimeout(function() {
                                            layer.close(lay);
                                        }, 1000);
                                        return;
                                    }
                                    layer.msg("删除失败", {
                                        icon: 2
                                    });

                                },
                                error: function(res) {
                                    layer.msg('服务器异常或网络原因', {
                                        icon: 2
                                    });
                                }
                            });
                        }

                    );
                    break;

            }

        });
</script>
</html>
